﻿$(function () {
    var scroll_timer;
    var displayed = false;
    var $message = $('#message a');
    var $window = $(window);
    var top = $(document.body).children(0).position().top;
    $window.scroll(function () {
        window.clearTimeout(scroll_timer);
        scroll_timer = window.setTimeout(function () {
            if ($window.scrollTop() <= top) {
                displayed = false;
                $message.fadeOut(500);
            }
            else if (displayed == false) {
                displayed = true;
                $message.stop(true, true).show().click(function () { $message.fadeOut(500); });
            }
        }, 100);
    });
});

$(document).ready(function () {
    $("#chbSelectAll").click(function () {
        var checked_status = this.checked;
        $(".marksend").each(function () {
            this.checked = checked_status && !this.disabled;
        });
    });

    $(".allIntro").click(function () {
        var selectedValue = this.parentNode.children[0].value;
        $(".introsender").each(function () {
            this.value = selectedValue;
        });
    });

    $(".allWinks").click(function () {
        var selectedValue = this.parentNode.children[0].value;
        $(".winkssender").each(function () {
            this.value = selectedValue;
        });
    });

    $(".allLimit").click(function () {
        var selectedValue = this.parentNode.children[0].value;
        $(".sendinglimit").each(function () {
            this.value = selectedValue;
        });
    });

    $(".allLocation").click(function () {
        var selectedValue = this.parentNode.children[0].value;
        $(".location").each(function () {
            this.value = selectedValue;
        });
    });

    $(".allSearchType").click(function () {
        var selectedValue = this.parentNode.children[0].value;
        $(".searchtypes").each(function () {
            this.value = selectedValue;
        });
    });

    $(".allPassword").click(function () {
        var selectedValue = this.parentNode.children[0].value;
        $(".profilePassword").each(function () {
            this.value = selectedValue;
        });
    });

    $(".allVideo").click(function () {
        var checked = this.parentNode.children[0].checked;
        $(".sendvideo").each(function () {
            this.checked = checked;
        });
    });

    $('ul#nav').NavDropDown({
        duration: 800,
        showEffect: 'fade'
    });

});

function updateStatus() {
    $(".sendingProgress").each(function () {
        $(this).hide();
    });
    $.ajax(
            {
                type: "POST",
                url: "/Profiles/UpdateStatus",
                success: function (data) {
                    if (data.activeProfiles.length > 0) {
                        for (var i = 0; i < data.activeProfiles.length; i++) {
                            $('#sending_status_' + data.activeProfiles[i]).show();
                        }
                    }
                }
            });
}



function StartSendAdminIntros() {
    $.ajax(
        {
            type: "POST",
            url: "/Settings/StartSendAdminIntros"
        });
}

function StopSendAdminIntros() {
    $.ajax(
        {
            type: "POST",
            url: "/Settings/StopSendAdminIntros"
        });
}

function StartSendProfileIntros() {
    $.ajax(
        {
            type: "POST",
            url: "/Settings/SendProfileIntros"
        });
}

function StartSendWinks() {
    $.ajax(
        {
            type: "POST",
            url: "/Settings/SendWinks"
        });
}

function StartSendAll() {
    $.ajax(
        {
            type: "POST",
            url: "/Settings/SendAll"
        });
}

function StopAll() {
    $.ajax(
        {
            type: "POST",
            url: "/Settings/StopAll"
        });
}

function SendAll(_profileId) {
    $.ajax(
        {
            type: "POST",
            url: "/Settings/ProfileSendAll",
            data: ({ profileId: _profileId })
        });
}